<?php
namespace Hive;
/**
 * Licensing Instance Object.
 * 
 * This instanct is use to handle the current user license authorization and
 * rights. In term of access, user number...
 * 
 * @package Hive
 * @author Xavier VILAIN
 * @license #license#
 */
class License {
	
	/**
	 * License Service
	 * @var string
	 */
	const SERVICE = 'hive-license-service';
	
	/**
	 * Max Authorized Number
	 */
	const USER_MAX_NUMBER = 'user-max-number';
	
	
	/**
	 * Singleton instance
	 *
	 * @var \Fox\Html\Steppers
	 */
	private static $_instance;

	/**
	 * Retrieve singleton instance
	 *
	 * @return Customizing
	 */
	public static function instance()
	{
		if (null === self::$_instance) {
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	
	/**
	 * License Property Get
	 * This method calls the licensing ws to 
	 * get the value of the passed property
	 * @param string $property
	 * @return mixed
	 */
	public function get($property) {

		// Cloudname is a unique account number
		$cloudname = User::current()->cloudname();
		// 
		$requestBody = array("cloudname" => $cloudname,
							 "token" => _APPLICATION_TOKEN_,
							 "property" => $property);
		// 
		try {
			$res = Services::instance()->service('hive-missions')->call($requestBody);
			$result = json_decode($res,true);
			if(is_array($result) && isset($result['value'])) {
				return $result['value'];
			} else {
				return false;
			}
		}
		catch(\Exception $e) {
			Fox\Message::Error($e);
		}
	
	}
 }